<%@page import="study.itwill.team5.admin.AdminItem"%>
<%@page import="study.itwill.jsp.WebHandler"%>
<%@page import="study.itwill.team5.board.BoardItem"%>
<%@page import="java.util.ArrayList"%>
<%@page import="study.itwill.team5.board.Board"%>
<%@page import="study.itwill.common.PatternChecker"%>
<%@page import="study.itwill.common.DBHandler"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ include file="../session.jsp"%>
<%@ include file="../dbcon.jsp"%>
<%
	PatternChecker checker = PatternChecker.getInstance();

	int board_seq = web.getInt("board_seq");
	
	if (board_seq == -1) {
		db.disconnect();
		web.goPage(null, "파라미터가 잘못되었습니다.");
		return;
	}
	
	int house_seq = 0;
	int grade = 0;
	
	if (web.getInt("house_seq") > 0 && web.getInt("grade") > 0) {
		house_seq = web.getInt("house_seq");
		grade = web.getInt("grade");
	}
%>
<%
	/** 게시판 카테고리 조회 */
	Board board = new Board();
	ArrayList<BoardItem> list_board = board.listBoard(0);
	int category_seq = -1;
	for (int i=0; i<list_board.size(); i++) {
		BoardItem item = list_board.get(i);
		if (item.getSeq() == board_seq) {
			category_seq = item.getBoard_category_seq();
		}
	}
	
	boolean result = false;
	if (house_seq > 0 && grade > 0) {
		/** 데이터 저장 */
		result = board.deleteBoard(board_seq, house_seq, grade);
		
		if (result == false) {
			db.disconnect();
			web.goPage(null, "추가 실패했습니다.");
			return;
		}
	} else {
		/** 데이터 저장 */
		result = board.deleteBoard(board_seq);
		
		if (result == false) {
			db.disconnect();
			web.goPage(null, "추가 실패했습니다.");
			return;
		}
	}
	
	/** 접속 해제 */
	db.disconnect();
	
	if (!result) {
		web.goPage(null, "삭제에 실패했습니다.");
		return;
	}
	
	// 삭제 성공시 목록으로 이동
	web.goPage("listBoard.jsp?category=" + category_seq, null);
%>